package com.zhl.myspringtest.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;


@Aspect
@Component
@Slf4j
public class AspectService {

    @Pointcut("within(com.zhl.myspringtest.service.impl..*)")
    public void pointcut() {

    }

    @Before("execution(* com.zhl.myspringtest.service..*.*(..))")
    public void logInfoIn(JoinPoint joinPoint) throws Throwable {
        log.info("In : " +DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss.SSS").format(LocalDateTime.now()));
    }

    @After("execution(* com.zhl.myspringtest.service..*.*(..))")
    public void logInfoOut(JoinPoint joinPoint) throws Throwable {
        log.info("Out: "+DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss.SSS").format(LocalDateTime.now()));
    }
}
